#include <iostream>
#include <memory>
#include <pthread.h>
#include <vector>
#include "learn_5.hpp"

struct Address
{
    std::string city;
    std::string street;
    int number;

    REFLECT(city, street, number);
    // template <class Func> 
    // constexpr void for_each_members(Func&& func) 
    // { 
    //     func("city", city); 
    //     func("street", street);
    //     func("number", number)
    // };
};

struct Student
{
    std::string name;
    int age;
    Address address;

    REFLECT(name, age, address);
    // template <class Func>
    // constexpr void for_each_members(Func&& func) 
    // { 
    //     func("name", name);
    //     func("age", age);
    //     func("address", address); 
    // };
};

int main(void)
{
    Student stu = {"Tom", 20, Address{"Beijing", "Chaoyang Road", 100}};

    std::string bin = toString(serialize(stu));
    std::cout << bin << std::endl;

    auto stu2 = deserialize<Student>(fromString(bin));
    std::cout << "name: " << stu2.name << ", age: " << stu2.age 
              << ", address: " << stu2.address.city << ", "
              << stu2.address.street << ", " << stu2.address.number << std::endl;

    return 0;
}